package com.scau.classOnline.service;

import com.scau.classOnline.dao.MenuMapper;
import com.scau.classOnline.entity.Menu;
import com.scau.classOnline.common.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
@CacheConfig(cacheNames = "menus_cache")
public class MenuService {
    @Autowired
    MenuMapper menuMapper;

    public List<Menu> getAllMenu() {
        return menuMapper.selectAll();
    }

    public List<Menu> getMenusByUserId() {
        return menuMapper.selectByUserId(UserUtils.getCurrentUser().getId());
    }

    public List<Menu> menuTree() {
        return menuMapper.menuTree();
    }

    public List<Integer> getMenusByRid(Integer rid) {
        return menuMapper.selectByRoleId(rid);
    }
}
